/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module Printbuf.c - Printer buffer functions |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Print/printbuf.c $ 
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#include <project.h>
#define VSPRNBUF_C

#include <aclconio.h>
#include <string.h>
#include <errno.h>
#include <acldev.h>
#include <aclutil.h>
#include <amexhost.h>
#include <iso8583.h>


#ifdef DEBUG_VSPRNBUF
#define DEBUG_95
#endif

#include <define.h>
#include <ui.h>
#include <print.h>
#include <msg.h>
#include <printbuf.h>
#include <spdebug.h>

#ifdef MESSAGE_DUMP
/*-------------------------------------------------------------------------
    Function : vdPrintData()
    Description : xmits data defined by pchPkt out the serial port. Formats it
                  in hexadecimal form.
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      1      ?         ?        Creation.
      2    4/28/95   Eddy_B1    Moved it from vsprniso.c
--------------------------------------------------------------------------*/

void vdPrintData(char* pchTitle,unsigned char* pchPkt,int inPktSz) {
    int i,
    j;
    unsigned char c;
    unsigned char line[41];
    char szPrintBuffer[256];

    pdebug(("--vdPrintData--"));

    strcpy(szPrintBuffer, "\036");
    strcat(szPrintBuffer, pchTitle);
    strcat(szPrintBuffer, "\037\n\n");
    obPrinter.inPrint(&obPrinter, szPrintBuffer);
    i = 0;
    while (i < inPktSz) {
        sprintf((char *) line, "%3d   ", i);
        strcpy((char *) szPrintBuffer, (char *) line);
        j = 0;
        while ((i + j < inPktSz) && (j < 8)) {
            sprintf((char *) line, "%2X ", pchPkt[i + j]);
            if (line[0] == ' ')
                line[0] = '0';
            strcat((char *) szPrintBuffer, (char *) line);
            j++;
        }
        while (j++ < 8)
            strcat(szPrintBuffer, "   ");
        strcat(szPrintBuffer, "  ");
        strcpy((char *) line, " ");
        j = 0;
        while ((i + j < inPktSz) && (j < 8)) {
            c = pchPkt[i + j];
            if ((c < ' ') || (c > '~'))
                c = '.';
            line[0] = c;
            strcat((char *) szPrintBuffer, (char *) line);
            j++;
        }
        strcat(szPrintBuffer, "\n");
        obPrinter.inPrint(&obPrinter, szPrintBuffer);
        i += 8;
    }

    obPrinter.vdFormFeed(&obPrinter);
}

#endif /* MESSAGE_DUMP */

#undef VSPRNBUF_C

